package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seawaterbt.ssm.entity.*;
import com.seawaterbt.ssm.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ZhoneComplainInfo {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    @Autowired
    ZComplainInfoService zComplainInfoService;
    @Autowired CzBasHeatcompanyService basHeatcompanyService;
    @Autowired
    IComplainInfoService complainInfoService;

    public void pull(){
       QueryWrapper<ZComplainInfo> queryWrapper = new QueryWrapper<>();
       queryWrapper.eq("isOther",1).eq("wdtIsSync",0);
       List<ZComplainInfo> complainInfoList = zComplainInfoService.list(queryWrapper);
       if (complainInfoList != null){
           for (ZComplainInfo zComplainInfo:complainInfoList){
               QueryWrapper<ComplainInfo> complainInfoQueryWrapper = new QueryWrapper<>();
               complainInfoQueryWrapper.eq("code_city",zComplainInfo.getTransferItemCityID());
               ComplainInfo complainInfo = complainInfoService.getOne(complainInfoQueryWrapper);
               if (complainInfo == null){
                   complainInfo = new ComplainInfo();
               }
               complainInfo.setHouseHolder(zComplainInfo.getCusTelName());
               complainInfo.setAddress(zComplainInfo.getCusAddr());
               complainInfo.setArea(zComplainInfo.getRegionName());
               complainInfo.setAreaNote(zComplainInfo.getForDepartment());
               complainInfo.setCodeCity(zComplainInfo.getComplaintCode());
               complainInfo.setCloseTime(zComplainInfo.getRepairTime());
               complainInfo.setCommunityCode(zComplainInfo.getCommunityId());
               complainInfo.setCompanyCode(zComplainInfo.getHeatCompanyId());
               complainInfo.setCompanyNote(zComplainInfo.getForHeatCompany());
               complainInfo.setComplainLevel(1);//默认企业上报
               complainInfo.setSource(4);
               complainInfo.setComplainType(zComplainInfo.getComplainType());
               complainInfo.setHandleTime(zComplainInfo.getTimeLimit()+"");
               complainInfo.setStatus(zComplainInfo.getState());
               complainInfo.setStatusCounty(1);//默认县级审核
               complainInfoService.saveOrUpdate(complainInfo);
               zComplainInfo.setWdtIsSync(1);//设置为已同步
               zComplainInfoService.saveOrUpdate(zComplainInfo);
           }
       }
    }


}
